//
//  BJInsureButton.m
//  SZBank
//
//  Created by rimi on 16/7/19.
//  Copyright © 2016年 LuoYao. All rights reserved.
//

#import "BJInsureButton.h"

@interface BJInsureButton ()
{
    CGFloat frameWidth;//自身宽度
    CGFloat frameHeight;//自身高度
}
@property (nonatomic)UIImageView *headImageView;/**< 头部图片视图  */
@end
@implementation BJInsureButton

- (instancetype)initWithFrame:(CGRect)frame withDataArray:(NSArray *)dataArray
{
    self = [super initWithFrame:frame];
    if (self) {
        //给宽高赋值
        frameWidth = self.frame.size.width;
        frameHeight = self.frame.size.height;
        [self setBackgroundImage:[LocalDataManager getImageWithSourceOfPath:@"理财_背景"] forState:UIControlStateNormal];
        //给视图元素赋值
        self.headImageView.image = [LocalDataManager getImageWithURL:dataArray[0]];
        //添加头部图片视图
        [self addSubview:self.headImageView];
        //添加线条
        
        //添加label
        
        [self creatLabelsToViewWithDataArray:dataArray];
        
    }
    return self;
}



#pragma mark -- actions
- (void)creatLabelsToViewWithDataArray:(NSArray *)dataArray{
        //循环创建
    for (int i = 0; i < 6; i ++) {
        UILabel *label = [[UILabel alloc]init];

        label.text = dataArray[i + 1];
        label.font = [UIFont systemFontOfSize:FONT_SIZE];

        
        
        if (i < 2) {
            label.frame = CGRectMake(frameWidth * 0.26, i * frameHeight * 0.25,frameWidth * 0.7, frameHeight * 0.25);
            if (i == 0) {
                label.textColor = [UIColor whiteColor];
            }
        }else if (i < 4 && i > 1){
            label.frame = CGRectMake(frameWidth * 0.26, i * frameHeight * 0.25,frameWidth * 0.35, frameHeight * 0.25);
        }else{
            label.frame = CGRectMake(frameWidth * 0.62, (i - 2)* frameHeight * 0.25,frameWidth * 0.35, frameHeight * 0.25);
        }
        
        [self addSubview:label];
    }
}






#pragma mark -- getters
- (UIImageView *)headImageView{
    if (!_headImageView) {
        _headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frameWidth * 0.25, frameHeight )];
    }
    
    return _headImageView;
}









@end







